#region Microsoft Public License
/*
 * (c) Copyright Chenjun Wu. http://utablesdk.codeplex.com
 * 
 * This source is subject to the Microsoft Public License (Ms-PL).
 * Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
 * All other rights reserved.
 */
#endregion

﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows;
using System.Globalization;

namespace UTable.Objects.Controls
{
    [ValueConversion(typeof(bool), typeof(Visibility))]
    public class BooleanVisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type typeTarget, object param, CultureInfo culture)
        {
            object result = value;
            if (value != null && typeTarget == typeof(Visibility))
            {
                return (bool)value ? Visibility.Visible : Visibility.Hidden;
            }
            if (value == null)
                return Visibility.Hidden;
            return result;
        }
        public object ConvertBack(object value, Type typeTarget, object param, CultureInfo culture)
        {
            object result = value;
            if (value != null && typeTarget == typeof(bool))
            {
                result = (Visibility)value == Visibility.Visible ? true : false;
            }
            return result;
        }
    }
}
